package myultility;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Exec {
	public String error=null,result=null;
	private String[] cmd;
	public boolean exe(int wait){
		int t=0;
		try {
			Process p = Runtime.getRuntime().exec(cmd);
			try {
				while(p.getErrorStream().available()==0 && p.getInputStream().available()==0){
					Thread.sleep(10);
					if(t++>wait)return false;
				}
				BufferedReader input =new BufferedReader(new InputStreamReader(p.getInputStream()));
				if(input.ready()){
					result=input.readLine();
				}else{
					input=new BufferedReader(new InputStreamReader(p.getErrorStream()));
					if(input.ready()){
						error=input.readLine();
					}else{
						error="Unknown";
					}
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}catch (Exception err){
			error=err.toString();
		}
		return true;
	}
	public Exec(String[] command){
		cmd=command;
		System.out.println(command);
	}
}
